package com.suyang.syt.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.suyang.syt.dao.interfaces.UserRoleDao;
import com.suyang.syt.model.UserRole;

@Repository
public class UserRoleDaoImpl extends BaseDaoImpl<UserRole> implements UserRoleDao {

	@Override
	public void deleteUserRoles(String userIds) {
		String hql = " delete from UserRole ur where ur.userId in(" + userIds + ") ";
		this.executeByHql(hql);
	}

	@Override
	public List<UserRole> listUserRoles(long userId) {
		String hql = " from UserRole ur where ur.userId=? ";
		return list(hql, userId);
	}

	@Override
	public boolean theExistenceUserId(long userid, long roleid) {
		String hql = " select count(*) from UserRole u where u.userId=? and roleId=?";
		Long result = (Long) this.queryByHql(hql, new Object[] { userid, roleid });
		if (result > 0) {
			return true;
		}
		return false;
	}

	@Override
	public void deletes(String ids) {
		String hql = " delete from UserRole where id in(" + ids + ")";
		this.executeByHql(hql);
	}

	@Override
	public long countUserRole(long userId, long roleId) {
		String hql = " select count(*) from UserRole where userId=? and roleId=?";
		return (Long) this.queryByHql(hql, new Object[] { userId, roleId });
	}

	@Override
	public long countUserRole(String roleIds) {
		String hql = " select count(*) from UserRole where roleId in(" + roleIds + ")";
		return (Long) this.queryByHql(hql);
	}

	@Override
	public void clearUsers(String roleIds) {
		String hql = " delete from UserRole where roleId in(" + roleIds + ")";
		this.executeByHql(hql);
	}

}